/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.dao.addxuonghibernate;

import model.dao.AbstractQuery;
import model.dao.loai.LoaiDAO;
import model.entity.ChungLoai;
import model.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author Admin
 */
public class ChungLoaiDAO {
    private static String LOAD_1_CL = "FROM ChungLoai cl WHERE cl.clMa =";
    public static final int insertChungLoai(ChungLoai cLoai){
//        AbstractQuery.insertObject(ct.getLoai());
//        AbstractQuery.insertObject(ct);
        Session session = HibernateUtil.getSessionFactory().openSession();
        int id;
        try {
            LoaiDAO.insertLoai(cLoai.getLoai());
            session.beginTransaction();
            session.save(cLoai);
            session.getTransaction().commit();
            id = cLoai.getClMa();
        } catch (HibernateException e) {
            session.getTransaction().rollback();
            throw  new HibernateException(e);
        }finally{
            session.close();
        }
        return id;
        
        
    }
     public static  void deleteCL(int clMa){
        AbstractQuery.modifyObject(3, AbstractQuery.loadObject(LOAD_1_CL + clMa).get(0));
    }
    
}
